from pprint import pprint

classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes.sort(key=lambda x: x['grade'])    # 1. 根据 grade 排序
pprint(classes)

f = filter(lambda x: x['grade'] == 'A', classes)    # 2. 筛选出 grade 为 A 的同学
pprint(list(f))


def age_add(a):
    return a['age'] + 1


c = map(age_add, classes)     # 3. 将上述 age + 1
pprint(list(c))



#重构斐波那契数列
def f(n):

    if n <= 1:
        return n
    return f(n - 1) + f(n - 2)


for i in range(13):
    print(f(i))
